//
//  CreateJobReviewSiteAttributesView.swift
//  GreenDeal
//
//  Created by Moennig Q on 2023/3/16.
//

import UIKit
import SnapKit
class CreateJobReviewSiteAttributesView: View {
    let titleView = CreateJobReviewSectionView(R.string.localizable.siteAttributes().uppercased(),haveEditBtnFlag: true)
    let storyText = ContentLabel(R.font.interMedium(size: 13))
    let roofText = ContentLabel(R.font.interMedium(size: 13))
    let panelTypeText = ContentLabel(R.font.interMedium(size: 13))
    let phaseText = ContentLabel(R.font.interMedium(size: 13))
    let mountingTypeText = ContentLabel(R.font.interMedium(size: 13))
    override func setUpView() {
        //titleView
        self.addSubview(titleView)
        titleView.snp.makeConstraints { make in
            make.top.left.right.equalToSuperview()
            make.height.greaterThanOrEqualTo(0)
        }
        //story
        let storyTitle = ContentLabel(R.font.interMedium(size: 13),hexStr: "#292D3280")
        storyTitle.text = R.string.localizable.story()
        self.addSubview(storyTitle)
        storyTitle.snp.makeConstraints { make in
            make.top.equalTo(titleView.snp.bottom).offset(16)
            make.left.equalTo(16)
            make.height.width.greaterThanOrEqualTo(0)
        }
        //
        storyText.numberOfLines = 0
        storyText.textAlignment = .right
        self.addSubview(storyText)
        storyText.snp.makeConstraints { make in
            make.left.equalTo(storyTitle.snp.right).offset(5)
            make.top.equalTo(storyTitle)
            make.right.equalTo(-16)
            make.height.greaterThanOrEqualTo(storyTitle)
        }
        
        //mounting type
        let mountingTypeTitle = ContentLabel(R.font.interMedium(size: 13),hexStr: "#292D3280")
        mountingTypeTitle.text = R.string.localizable.systemMountingType()
        mountingTypeTitle.setContentHuggingPriority(.required, for: NSLayoutConstraint.Axis.horizontal)
        mountingTypeTitle.setContentCompressionResistancePriority(.required, for: NSLayoutConstraint.Axis.horizontal)
        self.addSubview(mountingTypeTitle)
        mountingTypeTitle.snp.makeConstraints { make in
            make.top.equalTo(storyText.snp.bottom).offset(12)
            make.left.equalTo(storyTitle)
            make.height.width.greaterThanOrEqualTo(0)
        }
        //
        mountingTypeText.numberOfLines = 0
        mountingTypeText.textAlignment = .right
        self.addSubview(mountingTypeText)
        mountingTypeText.snp.makeConstraints { make in
            make.left.equalTo(mountingTypeTitle.snp.right).offset(5)
            make.top.equalTo(mountingTypeTitle)
            make.right.equalTo(storyText)
            make.height.greaterThanOrEqualTo(mountingTypeTitle)
        }
        //roof
        let roofTitle = ContentLabel(R.font.interMedium(size: 13),hexStr: "#292D3280")
        roofTitle.text = R.string.localizable.roof()
        self.addSubview(roofTitle)
        roofTitle.snp.makeConstraints { make in
            make.top.equalTo(mountingTypeText.snp.bottom).offset(12)
            make.left.equalTo(storyTitle)
            make.height.width.greaterThanOrEqualTo(0)
        }
        //
        roofText.numberOfLines = 0
        roofText.textAlignment = .right
        self.addSubview(roofText)
        roofText.snp.makeConstraints { make in
            make.left.equalTo(roofTitle.snp.right).offset(5)
            make.top.equalTo(roofTitle)
            make.right.equalTo(storyText)
            make.height.greaterThanOrEqualTo(roofTitle)
        }
        //panelType
        let panelTypeTitle = ContentLabel(R.font.interMedium(size: 13),hexStr: "#292D3280")
        panelTypeTitle.text = R.string.localizable.panelType()
        self.addSubview(panelTypeTitle)
        panelTypeTitle.snp.makeConstraints { make in
            make.top.equalTo(roofText.snp.bottom).offset(12)
            make.left.equalTo(storyTitle)
            make.height.width.greaterThanOrEqualTo(0)
        }
        //
        panelTypeText.numberOfLines = 0
        panelTypeText.textAlignment = .right
        self.addSubview(panelTypeText)
        panelTypeText.snp.makeConstraints { make in
            make.left.equalTo(panelTypeTitle.snp.right).offset(5)
            make.top.equalTo(panelTypeTitle)
            make.right.equalTo(storyText)
            make.height.greaterThanOrEqualTo(panelTypeTitle)
        }
        
        //phase
        let phaseTitle = ContentLabel(R.font.interMedium(size: 13),hexStr: "#292D3280")
        phaseTitle.text = R.string.localizable.phase()
        self.addSubview(phaseTitle)
        phaseTitle.snp.makeConstraints { make in
            make.top.equalTo(panelTypeText.snp.bottom).offset(12)
            make.left.equalTo(storyTitle)
            make.height.width.greaterThanOrEqualTo(0)
        }
        //
        phaseText.numberOfLines = 0
        phaseText.textAlignment = .right
        self.addSubview(phaseText)
        phaseText.snp.makeConstraints { make in
            make.left.equalTo(phaseTitle.snp.right).offset(5)
            make.top.equalTo(phaseTitle)
            make.right.equalTo(storyText)
            make.height.greaterThanOrEqualTo(phaseTitle)
            make.bottom.equalTo(-16)
        }
    }
    func setData(){
        //story
        let story = CreateJobModelHelper.shared.createJobViewModel.siteAttributesViewModel.story
        if story == .SingleStory {
            self.storyText.text = R.string.localizable.single()
        }else if story == .MultiStory {
            self.storyText.text = R.string.localizable.multi()
        }
        //roof
        self.roofText.text = CreateJobModelHelper.shared.createJobViewModel.siteAttributesViewModel.roof.rawValue
        //panel type
        self.panelTypeText.text = CreateJobModelHelper.shared.createJobViewModel.siteAttributesViewModel.panel_type.rawValue
        //phase
        self.phaseText.text = CreateJobModelHelper.shared.createJobViewModel.siteAttributesViewModel.phase.rawValue
        //mounting type
        let mountingType = CreateJobModelHelper.shared.createJobViewModel.siteAttributesViewModel.install_on_building
        if mountingType == .BuildOnBuiding{
            self.mountingTypeText.text = R.string.localizable.buildingOrStructure()
        }else if mountingType == .NotBuildOnBuiding{
            self.mountingTypeText.text = R.string.localizable.groundMountedOrFreeStand()
        }else{
            self.mountingTypeText.text = ""
        }
    }
}
